﻿#ifndef QLUA_H
#define QLUA_H

#include <QObject>
#include <QFile>
#include <QDebug>
#include <QWidget>
#include <QLineEdit>
#include <QPushButton>
#include <QMessageBox>

extern "C"
{
#include "lualib.h"
#include "lauxlib.h"
#include "tolua++.h"
}

class QLua : public QObject
{
    Q_OBJECT
public:
    QLua(QObject *parent = 0);
    ~QLua();

    // lua
    void init();
    void close();

    void pushFunction(QString funcName, lua_CFunction func);

    void getGlobal(QString value);

    void beginModule(QString);
    void addType(QString, lua_CFunction deleteFunc);
    void moduleTypeFunction(QString, lua_CFunction);
    void endModule();

    void run(QString);
    void loadFile(QString fileName);
    void pcall(int nargs, int nresults, int errfunc);

    void pushNumber(lua_Number value);
    bool isNumber(int idx);
    double toNumber(int idx);

    void pushString(QString value);
    bool isString(int idx);
    QString toString(int idx);

    void pop(int num = 1);

signals:

public slots:

private:
    lua_State *L;

    bool isStartModule;
};

#endif // QLUA_H
